<template>
<el-dialog title="编辑客户基本信息" :visible.sync="visible" append-to-body width="500px">
    <el-form :model="ruleForm" ref="ruleFormDialog" :rules="rules" label-width="80px" label-position="left">
        <el-form-item label="客户姓名" prop="fullname">
            <el-input v-model="ruleForm.fullname" placeholder="请输入客户姓名"></el-input>
        </el-form-item>

        <el-form-item label="性别">
            <el-radio-group v-model="ruleForm.sex">
                <el-radio v-for="item in sexOpts" :key="item.id" :label="item.id">{{item.title}}</el-radio>
            </el-radio-group>
        </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
    </div>
</el-dialog>
</template>

<script>
import {
    getFormToken
} from "@/api/system/system";
import {
    saveMemberBaseApi
} from '@/api/customer/member.js'
const ruleForm = {
    fullname: "",
    sex: 2,
    form_token:""
};

export default {
    data() {
        return {
            visible: false,
            ruleForm: Object.assign({}, ruleForm),
            sexOpts: [{
                id: 1,
                title: "男"
            }, {
                id: 2,
                title: "女"
            }, {
                id: 3,
                title: "未知"
            }],
            rules: {

            }
        }
    },
    methods: {
        showDialog(options){
            this.visible = true;
            options.form_token = "";
            this.ruleForm = options;
            getFormToken({
                api: "/api/customer.member/save",
            }).then(res => {
                this.ruleForm.form_token = res.data.token;
            });
        },
        closeDialog() {
            this.visible = false;
        },
        submit() {
            this.$refs['ruleFormDialog'].validate((valid) => {
                if (!valid) {
                    return false;
                }

                saveMemberBaseApi(this.ruleForm).then(res => {
                    this.closeDialog();
                    if (res.code == '200') {
                        this.$message.success(res.msg);
                    } else {
                        this.$message.error(res.msg);
                    }
                })
            })
        }
    }
}
</script>

<style>

</style>
